﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;

namespace YArchitech.Plumbing
{
	public class HideWarningAndErroringKit
	{
		public HideWarningAndErroringKit(List<string> lstTransactionName, HideWarningAndErroringKit.HideKitEnum hidKieEnum)
		{
			this.m_lstTransactionName = lstTransactionName;
			this.m_HidKitEnum = hidKieEnum;
		}

		public void OnFailuresProcessing(object sender, FailuresProcessingEventArgs e)
		{
			FailuresAccessor failuresAccessor = e.GetFailuresAccessor();
			string transactionName = failuresAccessor.GetTransactionName();
			IList<FailureMessageAccessor> failureMessages = failuresAccessor.GetFailureMessages();
			if (failureMessages.Count == 0)
			{
				e.SetProcessingResult((FailureProcessingResult)0);
				return;
			}
			if (this.m_lstTransactionName.IndexOf(transactionName) != -1)
			{
				foreach (FailureMessageAccessor failureMessageAccessor in failureMessages)
				{
					switch (this.m_HidKitEnum)
					{
					case HideWarningAndErroringKit.HideKitEnum.HideWarning:
						if ((int)failureMessageAccessor.GetSeverity() == 1)
						{
							failuresAccessor.DeleteWarning(failureMessageAccessor);
						}
						break;
					case HideWarningAndErroringKit.HideKitEnum.HideErroring:
						if ((int)failureMessageAccessor.GetSeverity() == 2)
						{
							failuresAccessor.ResolveFailure(failureMessageAccessor);
						}
						break;
					case HideWarningAndErroringKit.HideKitEnum.HideErroringAndWarning:
						if ((int)failureMessageAccessor.GetSeverity() == 1)
						{
							failuresAccessor.DeleteWarning(failureMessageAccessor);
						}
						else if ((int)failureMessageAccessor.GetSeverity() == 2)
						{
							failuresAccessor.ResolveFailure(failureMessageAccessor);
						}
						break;
					}
				}
				e.SetProcessingResult((FailureProcessingResult)1);
				return;
			}
			e.SetProcessingResult((FailureProcessingResult)0);
		}

		public void OnFailuresProcessingDelAllWaring(object sender, FailuresProcessingEventArgs e)
		{
			FailuresAccessor failuresAccessor = e.GetFailuresAccessor();
			string transactionName = failuresAccessor.GetTransactionName();
			if (failuresAccessor.GetFailureMessages().Count == 0)
			{
				e.SetProcessingResult((FailureProcessingResult)0);
				return;
			}
			if (this.m_lstTransactionName.IndexOf(transactionName) != -1)
			{
				failuresAccessor.DeleteAllWarnings();
				e.SetProcessingResult((FailureProcessingResult)1);
				return;
			}
			e.SetProcessingResult((FailureProcessingResult)0);
		}

		private List<string> m_lstTransactionName;

		private HideWarningAndErroringKit.HideKitEnum m_HidKitEnum = HideWarningAndErroringKit.HideKitEnum.HideNothing;

		public enum HideKitEnum
		{
			HideWarning,
			HideErroring,
			HideErroringAndWarning,
			HideNothing
		}
	}
}
